// Ionic Starter App

// angular.module is a global place for creating, registering and retrieving Angular modules
// 'starter' is the name of this angular module example (also set in a <body> attribute in index.html)
// the 2nd parameter is an array of 'requires'

angular.module('starter', ['ionic'])

  .controller("ExampleController", function ($scope) {

    $scope.openInAppBrowserGoogle = function () {
      // Open in app browser
      var ref = window.open('https://www.google.com.hk', '_blank', 'location=no');
    };

    $scope.openInAppBrowser = function () {
      // Open in app browser
      var ref = window.open('https://fanyi.baidu.com', '_blank', 'location=no,hidden=yes,hardwareback=no');
      insertCSS(ref, "css/baidu_fanyi.css");
    };

    $scope.openInAppBrowser2 = function () {
      // Open in app browser
      var ref = window.open('https://m.taobao.com/#index', '_self', 'location=no');
      insertJS(ref, "js/taobao.js");
    };

    $scope.openInAppBrowserTaobaoLogin = function () {
      // Open in app browser
      var ref = window.open('https://login.m.taobao.com/login.htm?spm=0.0.0.0&nv=true', '_self', 'location=no');
      insertJS(ref, "js/taobao.js");
    };

    $scope.openInAppBrowserTaobaoMe = function () {
      // Open in app browser
      var ref = window.open('http://h5.m.taobao.com/mlapp/mytaobao.html#mlapp-mytaobao', '_self', 'location=no');
      insertJS(ref, "js/taobao.js");
    };

    $scope.openCordovaWebViewJD = function () {
      // Open cordova webview if the url is in the whitelist otherwise opens in app browser
      window.open('https://plogin.m.jd.com/user/login.action?appid=100&kpkey=', '_self', 'location=no');
    };
  })

.run(function($ionicPlatform) {
  $ionicPlatform.ready(function() {
    if(window.cordova && window.cordova.plugins.Keyboard) {
      // Hide the accessory bar by default (remove this to show the accessory bar above the keyboard
      // for form inputs)
      cordova.plugins.Keyboard.hideKeyboardAccessoryBar(true);

      // Don't remove this line unless you know what you are doing. It stops the viewport
      // from snapping when text inputs are focused. Ionic handles this internally for
      // a much nicer keyboard experience.
      cordova.plugins.Keyboard.disableScroll(true);
    }
    if(window.StatusBar) {
      StatusBar.styleDefault();
    }
  });
});


